package win.smartown.library.easyAdapter;

import android.support.annotation.IdRes;
import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * Author:Tiger
 * <p>
 * CrateTime:2017/2/22 14:37
 * <p>
 * Description:
 */
public final class EasyViewHolder extends RecyclerView.ViewHolder {

    private SparseArray<View> views;

    public EasyViewHolder(View itemView) {
        super(itemView);
        views = new SparseArray<>();
    }

    public View getView(@IdRes int viewId) {
        View view = views.get(viewId);
        if (view == null) {
            view = itemView.findViewById(viewId);
            views.put(viewId, view);
        }
        return view;
    }

    public TextView getTextView(@IdRes int viewId) {
        return (TextView) getView(viewId);
    }

    public ImageView getImageView(@IdRes int viewId) {
        return (ImageView) getView(viewId);
    }

    public EditText getEditText(@IdRes int viewId) {
        return (EditText) getView(viewId);
    }

}
